//
//  BannerCell.swift
//  SwiftBannerView
//
//  Created by iOS on 2020/8/26.
//

import UIKit



///内置基础样式,更多样式请自定义,并注册
public class PageCell: UICollectionViewCell {
    public var imageView = UIImageView()
    override init(frame: CGRect) {
        super.init(frame: frame)
        imageView.clipsToBounds = true
        imageView.frame = bounds
        imageView.image = UIImage(named: kCommonPlaceholder)
        imageView.contentMode = .scaleAspectFill
        contentView.addSubview(imageView)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}


public class PageCustomCell: UICollectionViewCell {
    var routeModel: SSBanner? {
        didSet {
            guard routeModel != nil else { return }
            if routeModel?.isLocationImg == true {
                cardImgView.image = UIImage(named: routeModel?.bgName ?? "")
            }else{
                cardImgView.setImage(with: routeModel?.imgUrl, placeholderImage: UIImage(named: "banner_place_holder"))
//                cardImgView.setImage(with: "https://img1.baidu.com/it/u=2154540390,2157561636&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=247", placeholderImage: UIImage(named: routeModel?.bgName ?? ""))
            }
        }
    }
    public var topCardView = UIView()
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupCellViews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func setupCellViews() {
        
        contentView.addSubview(cardImgView)
        cardImgView.addSubview(badgeImgView)
        
        cardImgView.snp.makeConstraints { m in
            m.edges.equalToSuperview()
        }
        badgeImgView.snp.makeConstraints { m in
            m.width.height.equalTo(62)
            m.top.equalToSuperview().offset(28)
            m.right.equalToSuperview().offset(-21)
        }
    }
    ///懒加载
    fileprivate lazy var cardImgView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = UIImage.init(named: "img_welfare_card")
        imageView.isUserInteractionEnabled = true
//        imageView.contentMode = .scaleAspectFill
        imageView.layer.masksToBounds = true
        imageView.layer.cornerRadius = 8
        imageView.clipsToBounds = true
        
        return imageView
    }()
    
    fileprivate lazy var badgeImgView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = UIImage.init(named: "img_welfare_badge")
        imageView.contentMode = .scaleAspectFill
        imageView.clipsToBounds = true
        return imageView
    }()
}
